home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / tie / src / vram.asm < prev    next >
Assembly Source File  |  1991-10-18  |  19KB  |  498 lines

  1. ;*************************************
  2. ;       VRAM Direct Access Program
  3. ;*************************************
  4.  
  5. extrn   page_ofs:dword
  6.  
  7. bitptn  segment 'DATA'
  8.  
  9. ;*************************************
  10. ;       16色VRAMビットパタ-ン
  11. ;*************************************
  12.  
  13. ankfnt  dd      16*256 dup(?)
  14. fntcol  dd      256 dup(?)
  15. fntptn  dd      000000000h,0F0000000h,00F000000h,0FF000000h
  16.         dd      000F00000h,0F0F00000h,00FF00000h,0FFF00000h
  17.         dd      0000F0000h,0F00F0000h,00F0F0000h,0FF0F0000h
  18.         dd      000FF0000h,0F0FF0000h,00FFF0000h,0FFFF0000h
  19.         dd      00000F000h,0F000F000h,00F00F000h,0FF00F000h
  20.         dd      000F0F000h,0F0F0F000h,00FF0F000h,0FFF0F000h
  21.         dd      0000FF000h,0F00FF000h,00F0FF000h,0FF0FF000h
  22.         dd      000FFF000h,0F0FFF000h,00FFFF000h,0FFFFF000h
  23.         dd      000000F00h,0F0000F00h,00F000F00h,0FF000F00h
  24.         dd      000F00F00h,0F0F00F00h,00FF00F00h,0FFF00F00h
  25.         dd      0000F0F00h,0F00F0F00h,00F0F0F00h,0FF0F0F00h
  26.         dd      000FF0F00h,0F0FF0F00h,00FFF0F00h,0FFFF0F00h
  27.         dd      00000FF00h,0F000FF00h,00F00FF00h,0FF00FF00h
  28.         dd      000F0FF00h,0F0F0FF00h,00FF0FF00h,0FFF0FF00h
  29.         dd      0000FFF00h,0F00FFF00h,00F0FFF00h,0FF0FFF00h
  30.         dd      000FFFF00h,0F0FFFF00h,00FFFFF00h,0FFFFFF00h
  31.         dd      0000000F0h,0F00000F0h,00F0000F0h,0FF0000F0h
  32.         dd      000F000F0h,0F0F000F0h,00FF000F0h,0FFF000F0h
  33.         dd      0000F00F0h,0F00F00F0h,00F0F00F0h,0FF0F00F0h
  34.         dd      000FF00F0h,0F0FF00F0h,00FFF00F0h,0FFFF00F0h
  35.         dd      00000F0F0h,0F000F0F0h,00F00F0F0h,0FF00F0F0h
  36.         dd      000F0F0F0h,0F0F0F0F0h,00FF0F0F0h,0FFF0F0F0h
  37.         dd      0000FF0F0h,0F00FF0F0h,00F0FF0F0h,0FF0FF0F0h
  38.         dd      000FFF0F0h,0F0FFF0F0h,00FFFF0F0h,0FFFFF0F0h
  39.         dd      000000FF0h,0F0000FF0h,00F000FF0h,0FF000FF0h
  40.         dd      000F00FF0h,0F0F00FF0h,00FF00FF0h,0FFF00FF0h
  41.         dd      0000F0FF0h,0F00F0FF0h,00F0F0FF0h,0FF0F0FF0h
  42.         dd      000FF0FF0h,0F0FF0FF0h,00FFF0FF0h,0FFFF0FF0h
  43.         dd      00000FFF0h,0F000FFF0h,00F00FFF0h,0FF00FFF0h
  44.         dd      000F0FFF0h,0F0F0FFF0h,00FF0FFF0h,0FFF0FFF0h
  45.         dd      0000FFFF0h,0F00FFFF0h,00F0FFFF0h,0FF0FFFF0h
  46.         dd      000FFFFF0h,0F0FFFFF0h,00FFFFFF0h,0FFFFFFF0h
  47.         dd      00000000Fh,0F000000Fh,00F00000Fh,0FF00000Fh
  48.         dd      000F0000Fh,0F0F0000Fh,00FF0000Fh,0FFF0000Fh
  49.         dd      0000F000Fh,0F00F000Fh,00F0F000Fh,0FF0F000Fh
  50.         dd      000FF000Fh,0F0FF000Fh,00FFF000Fh,0FFFF000Fh
  51.         dd      00000F00Fh,0F000F00Fh,00F00F00Fh,0FF00F00Fh
  52.         dd      000F0F00Fh,0F0F0F00Fh,00FF0F00Fh,0FFF0F00Fh
  53.         dd      0000FF00Fh,0F00FF00Fh,00F0FF00Fh,0FF0FF00Fh
  54.         dd      000FFF00Fh,0F0FFF00Fh,00FFFF00Fh,0FFFFF00Fh
  55.         dd      000000F0Fh,0F0000F0Fh,00F000F0Fh,0FF000F0Fh
  56.         dd      000F00F0Fh,0F0F00F0Fh,00FF00F0Fh,0FFF00F0Fh
  57.         dd      0000F0F0Fh,0F00F0F0Fh,00F0F0F0Fh,0FF0F0F0Fh
  58.         dd      000FF0F0Fh,0F0FF0F0Fh,00FFF0F0Fh,0FFFF0F0Fh
  59.         dd      00000FF0Fh,0F000FF0Fh,00F00FF0Fh,0FF00FF0Fh
  60.         dd      000F0FF0Fh,0F0F0FF0Fh,00FF0FF0Fh,0FFF0FF0Fh
  61.         dd      0000FFF0Fh,0F00FFF0Fh,00F0FFF0Fh,0FF0FFF0Fh
  62.         dd      000FFFF0Fh,0F0FFFF0Fh,00FFFFF0Fh,0FFFFFF0Fh
  63.         dd      0000000FFh,0F00000FFh,00F0000FFh,0FF0000FFh
  64.         dd      000F000FFh,0F0F000FFh,00FF000FFh,0FFF000FFh
  65.         dd      0000F00FFh,0F00F00FFh,00F0F00FFh,0FF0F00FFh
  66.         dd      000FF00FFh,0F0FF00FFh,00FFF00FFh,0FFFF00FFh
  67.         dd      00000F0FFh,0F000F0FFh,00F00F0FFh,0FF00F0FFh
  68.         dd      000F0F0FFh,0F0F0F0FFh,00FF0F0FFh,0FFF0F0FFh
  69.         dd      0000FF0FFh,0F00FF0FFh,00F0FF0FFh,0FF0FF0FFh
  70.         dd      000FFF0FFh,0F0FFF0FFh,00FFFF0FFh,0FFFFF0FFh
  71.         dd      000000FFFh,0F0000FFFh,00F000FFFh,0FF000FFFh
  72.         dd      000F00FFFh,0F0F00FFFh,00FF00FFFh,0FFF00FFFh
  73.         dd      0000F0FFFh,0F00F0FFFh,00F0F0FFFh,0FF0F0FFFh
  74.         dd      000FF0FFFh,0F0FF0FFFh,00FFF0FFFh,0FFFF0FFFh
  75.         dd      00000FFFFh,0F000FFFFh,00F00FFFFh,0FF00FFFFh
  76.         dd      000F0FFFFh,0F0F0FFFFh,00FF0FFFFh,0FFF0FFFFh
  77.         dd      0000FFFFFh,0F00FFFFFh,00F0FFFFFh,0FF0FFFFFh
  78.         dd      000FFFFFFh,0F0FFFFFFh,00FFFFFFFh,0FFFFFFFFh
  79. ;**********************************************
  80. ;       漢字コ-ドチェックテ-ブル
  81. ;**********************************************
  82. ISKAN1  equ     1
  83. ISKAN2  equ     2
  84. ;               0 1 2 3 4 5 6 7 8 9 A B C D E F
  85. kantbl  db      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;0
  86.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;1
  87.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;2
  88.         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;3
  89.         db      2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 ;4
  90.         db      2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 ;5
  91.         db      2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 ;6
  92.         db      2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0 ;7
  93.         db      2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 ;8
  94.         db      3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 ;9
  95.         db      2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 ;A
  96.         db      2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 ;B
  97.         db      2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 ;C
  98.         db      2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 ;D
  99.         db      3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 ;E
  100.         db      3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0 ;F
  101. bitptn  ends
  102.  
  103. VRAM    segment 'CODE'
  104.         assume  cs:VRAM,ds:bitptn
  105. ;**************************************
  106. ;       String to VRAM Display
  107. ;**************************************
  108. ;   putstr(char *vram, char *str)
  109. ;               +8          +12
  110. ;**************************************
  111.         align   4                               ; align set
  112.         public  putstr
  113. putstr  proc    near
  114.         push    ebp
  115.         mov     ebp,esp
  116.         xor     eax,eax
  117.         push    eax                             ; work push
  118.  
  119.         push    gs
  120.         push    fs
  121.         push    es
  122.         push    esi
  123.         push    edi
  124.         push    edx
  125.         push    ecx
  126.         push    ebx
  127.         cld
  128.         mov     ax,104h                         ; VRAM Selecter
  129.         mov     es,ax                           ; es = VRAM Selecter
  130.         mov     ax,0110h                        ; TBIOS Selecter
  131.         mov     fs,ax                           ; fs = TBIOS
  132.         mov     ax,ds
  133.         mov     gs,ax                           ; gs = ds
  134.  
  135.         align   4                               ; align set
  136. putlop:                                         ; Put Loop
  137.         mov     esi,[ebp+12]                    ; char *str
  138.         lodsb                                   ; Get String    ※
  139.         or      al,al
  140.         je      Left_clear                      ; End of String ?
  141.  
  142.         movzx   eax,al
  143.         mov     bl,[eax+offset kantbl]
  144.         and     bl,ISKAN1
  145.         jz      putank                          ; Not iskanji1 ?
  146.         movzx   ebx,byte ptr [esi]
  147.         mov     bh,[ebx+offset kantbl]
  148.         and     bh,ISKAN2
  149.         jz      putank                          ; Not iskanji2 ?
  150.         mov     bh,al
  151.         inc     esi                             ; double_word ?????     ※
  152.         mov     [ebp+12],esi                    ; Save *str
  153.  
  154.         shl     bh,1                            ; Shift Jis to Jis
  155.         cmp     bl,080h
  156.         adc     bx,1f61h
  157.         add     bl,7fh
  158.         jc      short knf1
  159.         add     bl,0a2h
  160. knf1:   and     bh,7fh                          ; StoJ end
  161.  
  162.         mov     ax,0100h
  163.         mov     dx,1010h
  164.  
  165.         call    pword ptr fs:[00a0h]            ; Get Kanji Font
  166.  
  167.         mov     edi,ss:[ebp+8]                  ; *vram
  168.         add     edi,ss:[ebp-4]                  ; work add
  169.         or      edi,gs:[page_ofs]               ; or Page Offset
  170.         mov     ebx,offset fntcol
  171.         xor     edx,edx                         ; edx=0
  172.         xor     ecx,ecx                         ; ecx=0
  173.         REPT    16
  174.         lodsw                                   ; Get Kanji Font Pattern
  175.         mov     cl,al                           ; Left Font Pattern
  176.         mov     dl,ah                           ; Right Font Pattern
  177.         mov     eax,gs:[ebx+ecx*4]              ; Get Vram Bit Patan
  178.         stosd                                   ; Write Left Font 
  179.         mov     eax,gs:[ebx+edx*4]              ; Get Vram Bit Patan
  180.         stosd                                   ; Write Right Font
  181.         add     edi,512-4*2                     ; 1 Line 512 Byte
  182.         endm
  183.         mov     ax,gs
  184.         mov     ds,ax
  185.         add     dword ptr [ebp-4],8             ; Next vram Address
  186.  
  187.         jmp     putlop                          ; Next Put String Loop
  188.  
  189.         align   4                               ; align set
  190. putank:                                         ; Write Ank Font
  191.         mov     [ebp+12],esi                    ; Save *str
  192.         movzx   esi,al
  193.         shl     esi,6                           ; 4x16=64
  194.         add     esi,offset ankfnt               ; ANK Font Table Offset
  195.  
  196.         mov     edi,[ebp+8]                     ; *vram
  197.         add     edi,[ebp-4]                     ; work add
  198.         or      edi,[page_ofs]                  ; or Page Offset
  199.         mov     ebx,512-4
  200.         REPT    15
  201.         movsd                                   ; Trans Font
  202.         add     edi,ebx                         ; Line add
  203.         endm
  204.         movsd                                   ; Trans Font
  205.         add     dword ptr [ebp-4],4             ; Next vram Address
  206.  
  207.         jmp     putlop                          ; Next Put String Loop
  208.  
  209.         align   4
  210. Left_clear:
  211.         ; VRAM Clear
  212.         mov     ebx,320
  213.         sub     ebx,[ebp-4]                     ; nokori dword
  214.         je      nonclr
  215.  
  216.         mov     edi,[ebp+8]                     ; *vram
  217.         add     edi,[ebp-4]                     ; work add
  218.         or      edi,[page_ofs]                  ; or Page Offset
  219.         shr     ebx,2                           ; / 4
  220.         mov     ebp,[ebp-4]
  221.         add     ebp,512-320
  222.         mov     eax,[fntcol]
  223.         mov     edx,03FFFFh
  224.         mov     esi,[page_ofs]
  225.         REPT    16
  226.         mov     ecx,ebx                         ; nokori dword
  227.         rep     stosd
  228.         add     edi,ebp
  229.         and     edi,edx
  230.         or      edi,esi
  231.         endm
  232. nonclr:
  233.         ; end of VRAM Clear
  234.         pop     ebx
  235.         pop     ecx
  236.         pop     edx
  237.         pop     edi
  238.         pop     esi
  239.         pop     es
  240.         pop     fs
  241.         pop     gs
  242.  
  243.         pop     eax                             ; work pop
  244.         pop     ebp
  245.         ret                                     ; end of putstr
  246.  
  247. putstr  endp
  248. ;***************************************************
  249. ;       void    ctblset(int Chr_Col,int Bak_Col);
  250. ;***************************************************
  251.         public  ctblset
  252. ctblset proc    near
  253.         push    ebp
  254.         mov     ebp,esp
  255.         push    esi
  256.         push    edi
  257.         push    fs
  258.  
  259.         mov     ecx,256
  260.         mov     esi,offset fntptn
  261.         mov     edi,offset fntcol
  262. ctblp:  lodsd
  263.         mov     edx,eax
  264.         not     edx
  265.         and     eax,[ebp+8]
  266.         and     edx,[ebp+12]
  267.         or      eax,edx
  268.         stosd
  269.         loop    ctblp
  270.  
  271.         mov     ax,138h                         ; ANK Font Selecter
  272.         mov     fs,ax
  273.         mov     esi,3D800h
  274.         mov     edi,offset ankfnt
  275.  
  276.         mov     ecx,16*256
  277. aktb1:  movzx   eax,byte ptr fs:[esi]
  278.         inc     esi
  279.         mov     eax,[eax*4+fntcol]
  280.         stosd
  281.         loop    aktb1
  282.  
  283.         pop     fs
  284.         pop     edi
  285.         pop     esi
  286.         pop     ebp
  287.         ret
  288. ctblset endp
  289.         public  inport
  290. ;****************************************************************************
  291. ;   wrtstr(char *str, int page, char *vram, int forcol, int bakcol, int font)
  292. ;               +8        +12        +16        +20         +24         +28
  293. ;****************************************************************************
  294.         align   4                               ; align set
  295.         public  wrtstr
  296. wrtstr  proc    near
  297.         push    ebp
  298.         mov     ebp,esp
  299.         push    gs
  300.         push    fs
  301.         push    es
  302.         push    esi
  303.         push    edi
  304.         push    ebx
  305.  
  306.         mov     ax,104h                         ; VRAM Selecter
  307.         mov     gs,ax                           ; gs = VRAM Selecter
  308.         mov     ax,110h                         ; TBIOS Selecter
  309.         mov     fs,ax                           ; fs = TBIOS
  310.  
  311.         align   4                               ; align set
  312. wrtlop:                                         ; Put Loop
  313.         mov     esi,[ebp+8]                     ; char *str
  314.         movzx   eax,byte ptr [esi]
  315.         inc     si
  316.         or      al,al
  317.         jnz     short wrtnxt                    ; End of String ?
  318.  
  319.         pop     ebx
  320.         pop     edi
  321.         pop     esi
  322.         pop     es
  323.         pop     fs
  324.         pop     gs
  325.         pop     ebp
  326.         ret                                     ; end of putstr
  327.  
  328.         align   4                               ; align set
  329. wrtnxt:
  330.         mov     bl,[eax+offset kantbl]
  331.         and     bl,ISKAN1
  332.         jz      wrtank                          ; Not iskanji1 ?
  333.         movzx   ebx,byte ptr [esi]
  334.         mov     bh,[ebx+offset kantbl]
  335.         and     bh,ISKAN2
  336.         jz      wrtank                          ; Not iskanji2 ?
  337.         mov     bh,al
  338.         inc     si
  339.         mov     [ebp+8],esi                     ; Save *str
  340.  
  341.         shl     bh,1                            ; Shift Jis to Jis
  342.         cmp     bl,080h
  343.         adc     bx,1f61h
  344.         add     bl,7fh
  345.         jc      short wrtst1
  346.         add     bl,0a2h
  347. wrtst1: and     bh,7fh                          ; StoJ end
  348.  
  349.         mov     ax,0100h
  350.         mov     dx,1010h
  351.         push    ds
  352.         call    pword ptr fs:[00a0h]            ; Get Kanji Font
  353.         push    ds                              ; ds:esi = Kanji Font
  354.         pop     es                              ; cheng ds<->es
  355.         pop     ds
  356.  
  357.         mov     edi,[ebp+16]                    ; *vram
  358.         or      edi,[ebp+12]                    ; page
  359.         mov     ecx,[ebp+28]                    ; Y = 16 Dot Font
  360.         align   4                               ; align set
  361.  
  362. wtkn1:  mov     bx,es:[esi]
  363.         add     esi,2
  364.  
  365.         cmp     byte ptr [ebp+28],16
  366.         je      short wtkn2
  367.         or      bx,es:[esi]
  368.         add     esi,2
  369. wtkn2:
  370.         movzx   eax,bl                          ; Get Kanji Left Font Pattan
  371.         mov     eax,[eax*4+fntptn]              ; Get Vram Bit Patan
  372.         mov     edx,eax
  373.         not     edx
  374.         and     eax,[ebp+20]
  375.         and     edx,[ebp+24]
  376.         or      eax,edx
  377.         mov     gs:[edi],eax                    ; Write Kanji Left Font
  378.  
  379.         movzx   eax,bh                          ; Get Kanji Right Font Pattan
  380.         mov     eax,[eax*4+fntptn]              ; Get Vram Bit Patan
  381.         mov     edx,eax
  382.         not     edx
  383.         and     eax,[ebp+20]
  384.         and     edx,[ebp+24]
  385.         or      eax,edx
  386.         mov     gs:[edi+4],eax                  ; Write Kanji Right Font
  387.  
  388.         add     edi,512                         ; 1 Line 512 Byte
  389.         and     edi,03FFFFh
  390.         or      edi,[ebp+12]                    ; Page
  391.         loop    wtkn1
  392.  
  393.         add     dword ptr [ebp+16],8
  394.         jmp     wrtlop                          ; Next Put String Loop
  395.  
  396.         align   4                               ; align set
  397. wrtank:                                         ; Write Ank Font
  398.         cmp     al,1Bh                          ; Esc Code
  399.         jne     short wtak0
  400.  
  401.         movzx   eax,byte ptr [esi]
  402.         inc     esi
  403. wtak0:  mov     [ebp+8],esi                     ; Save *str
  404.         mov     esi,eax
  405.  
  406.         cmp     byte ptr [ebp+28],16
  407.         jne     short wrtft1
  408.         shl     esi,4                           ; x16
  409.         add     esi,3D800h                      ; 8x16 ANK Font Offset
  410.         jmp     short wrtft2
  411. wrtft1: shl     esi,3                           ; x8
  412.         add     esi,3D000h                      ; 8x8 ANK Font Offset
  413.  
  414. wrtft2: mov     ax,138h                         ; ANK Font Selecter
  415.         mov     es,ax
  416.  
  417.         mov     edi,[ebp+16]                    ; *vram
  418.         or      edi,[ebp+12]                    ; Page
  419.         mov     ecx,[ebp+28]                    ; Y = 16 Dot Font
  420.         align   4                               ; align set
  421.  
  422. wtak1:  movzx   eax,byte ptr es:[esi]           ; Get Font Pattan
  423.         inc     esi
  424.         mov     eax,[eax*4+fntptn]              ; Get Vram Bit Patan
  425.         mov     edx,eax
  426.         not     edx
  427.         and     eax,[ebp+20]
  428.         and     edx,[ebp+24]
  429.         or      eax,edx
  430.         mov     gs:[edi],eax                    ; Write Ank Font
  431.  
  432.         add     edi,512                         ; 1 Line 512 Byte
  433.         and     edi,03FFFFh
  434.         or      edi,[ebp+12]                    ; Page
  435.         loop    wtak1
  436.  
  437.         add     dword ptr [ebp+16],4
  438.  
  439.         jmp     wrtlop                          ; Next Put String Loop
  440.  
  441. wrtstr  endp
  442.  
  443. ;**************************************
  444. ;       int     inport(int portaddr)
  445. ;**************************************
  446. inport  proc    near
  447.         push    ebp
  448.         mov         ebp,esp
  449.         push    edx
  450.         mov         edx,[ebp+8]
  451.         xor         eax,eax
  452.         in          al,dx
  453.         pop         edx
  454.         pop         ebp
  455.         ret
  456. inport  endp
  457.  
  458. ;**************************************
  459. ;       VRAM Disp Start Addr Set
  460. ;**************************************
  461.         public  dsp_adr_set
  462. dsp_adr_set     proc    near
  463.         push    ebp
  464.         mov     ebp,esp
  465.         push    edx
  466.  
  467.         mov     dx,0440h
  468.         mov     al,21                   ; CRTC FA0
  469.         out     dx,al
  470.         mov     dx,0442h
  471.         mov     eax,[ebp+8]
  472.         out     dx,ax
  473.  
  474.         pop     edx
  475.         pop     ebp
  476.         ret
  477. dsp_adr_set    endp
  478.  
  479. ;**************************************
  480. ;   I/O Register access
  481. ;**************************************
  482.  
  483. ;void   outregw( port, num,data )
  484.  
  485.         public  outregw
  486. outregw proc    near
  487.         mov     dx,[esp+4]
  488.         mov     al,[esp+8]
  489.         out     dx,al
  490.         add     dx,2
  491.         mov     ax,[esp+12]
  492.         out     dx,ax
  493.         ret
  494. outregw endp
  495.  
  496. VRAM    ends
  497.         end
  498.